<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *客户列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'电销员数据'),
);
if($_SESSION['juese_id']>6 && $_SESSION['juese_id']<15){
	exi('您无权访问！','error');
}
//客户列表
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('juese'=>5,'status'=>1,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:30;
	$list=pdo_getslice('jy_yxw_worker',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$starttime = mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
		$weektime = $starttime+7*24*3600;
		$monthtime=strtotime(date('Ym').'01');
		$status4=array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,32,33,34,35,36,37,38,39,40,41,42,100);
		foreach($list as &$item){
			$item['member']=$this->model('worker')->member_show($item['id']);
			$item['allnum']=pdo_count('jy_yxw_member',array('worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['daynum']=pdo_count('jy_yxw_member',array('to5time >'=>$daytime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['weeknum']=pdo_count('jy_yxw_member',array('to5time >'=>$weektime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['monthnum']=pdo_count('jy_yxw_member',array('to5time >'=>$monthtime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['allnum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['daynum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$daytime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['weeknum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$weektime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['monthnum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$monthtime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['rate']=0;
			if($item['allnum']>0){
				$item['rate']=$item['allnum2']*100/$item['allnum'];
				$item['rate']=price($item['rate']);
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export',
		'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'电客员信息','type'=>'member'),
			array('name'=>'allnum','title'=>'总分量','type'=>'string'),
			array('name'=>'daynum','title'=>'当天分量','type'=>'string'),
			array('name'=>'weeknum','title'=>'当周分量','type'=>'string'),
			array('name'=>'monthnum','title'=>'当月分量','type'=>'string'),
			array('name'=>'allnum2','title'=>'总意向','type'=>'string'),
			array('name'=>'daynum2','title'=>'当天意向','type'=>'string'),
			array('name'=>'weeknum2','title'=>'当周意向','type'=>'string'),
			array('name'=>'monthnum2','title'=>'当月意向','type'=>'string'),
			array('name'=>'rate','title'=>'意向转化率','type'=>'unitstring','unit'=>'%'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'电客员名称','name'=>'title','help'=>''),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	//客户列表
	$return['params']=array();
	$params=array('juese'=>5,'status'=>1,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	$list=pdo_getall('jy_yxw_worker',$params,$fields);
	if($list){
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$starttime = mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
		$weektime = $starttime+7*24*3600;
		$monthtime=strtotime(date('Ym').'01');
		$status4=array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,32,33,34,35,36,37,38,39,40,41,42,100);
		foreach($list as &$item){
			$item['member']=$this->model('worker')->member_show($item['id']);
			$item['allnum']=pdo_count('jy_yxw_member',array('worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['daynum']=pdo_count('jy_yxw_member',array('to5time >'=>$daytime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['weeknum']=pdo_count('jy_yxw_member',array('to5time >'=>$weektime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['monthnum']=pdo_count('jy_yxw_member',array('to5time >'=>$monthtime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['allnum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['daynum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$daytime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['weeknum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$weektime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['monthnum2']=pdo_count('jy_yxw_member',array('status'=>$status4,'zhun_time >'=>$monthtime,'worker5id'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['rate']=0;
			if($item['allnum']>0){
				$item['rate']=$item['allnum2']*100/$item['allnum'];
				$item['rate']=price($item['rate']);
			}
			$item['rate'] .='%';
		}
	}
	$header=array(
		'title'=>'员工名称',
		'allnum'=>'总分量',
		'daynum'=>'当天分量',
		'weeknum'=>'当周分量',
		'monthnum'=>'当月分量',
		'allnum2'=>'总意向',
		'daynum2'=>'当天意向',
		'weeknum2'=>'当周意向',
		'monthnum2'=>'当月意向',
		'rate'=>'意向转化率',
	);
	model('core/tools')->export2excel($header,$list,'电客员数据');
}